<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>order管理</title>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <!-- 引入样式 -->
    <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
    <link href="../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }

        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理<small>order管理</small></h1>
        <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>order管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box" v-if="status==0">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true">
                    <el-form-item label="数量合计">
                        <el-input class="filter-item" placeholder="数量合计" v-model="searchMap.totalNum"></el-input>
                    </el-form-item>
                    <el-form-item label="交易完成时间">
                        <el-input class="filter-item" placeholder="交易完成时间" v-model="searchMap.endTime"></el-input>
                    </el-form-item>

                    <el-form-item label="用户名称">
                        <el-input class="filter-item" placeholder="用户名称" v-model="searchMap.username"></el-input>
                    </el-form-item>
                    <el-form-item label="收货人">
                        <el-input class="filter-item" placeholder="收货人" v-model="searchMap.receiverContact"></el-input>
                    </el-form-item>
                    <el-button @click="fetchData()" class="dalfBut">查询</el-button>
                    <el-button @click="formVisible=true;pojo={}" class="butT" type="primary">新增</el-button>
                </el-form>
            </div>

            <div class="content">
                <div style="width: 100% ;height: 60px;background-color: rgba(249, 249, 249, 1)">

                    <el-row style="position: relative">
                        <span style="position: absolute;top: 20px;left: 80px">数据列表</span>

                        <div style="position: absolute;top: 10px; right: 180px">
                            <el-button @click="formVisible=true;title='拆分订单'" type="primary">拆分订单</el-button>
                            <el-button @click='formVisible=true;title="合并订单"' type="success">合并订单</el-button>
                            <el-button type="info">打印发货单</el-button>
                            <el-button @click="findList()" type="warning">批量发货</el-button>
                            <el-button type="danger">导出订单</el-button>
                        </div>
                    </el-row>
                </div>
                <el-table :data="tableData" @selection-change="handleSelectionChange" border ref="multipleTable"
                          style="width: 100%">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column label="订单编号" prop="id" width="160"></el-table-column>
                    <el-table-column label="订单数量" prop="totalNum" width="80"></el-table-column>
                    <el-table-column label="实付金额" prop="payMoney" width="80"></el-table-column>
                    <el-table-column label="支付类型" width="80">
                        <template slot-scope="scope">
                            <span v-if="scope.row.payType==1">在线支付</span>
                            <span v-else>货到支付</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="付款时间" prop="payTime" width="160"></el-table-column>
                    <el-table-column label="订单来源" prop="sourceType" width="80">
                        <template slot-scope="scope">
                            <span v-if="scope.row.sourceType==1">web</span>
                            <span v-else-if="scope.row.sourceType==2">app</span>
                            <span v-else-if="scope.row.sourceType==3">微信公众号</span>
                            <span v-else-if="scope.row.sourceType==4">微信小程序</span>
                            <span v-else>H5页面</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="订单状态" width="80">
                        <template slot-scope="scope">
                            <span v-if="scope.row.orderStatus==0">待付款</span>
                            <span v-else-if="scope.row.orderStatus==1">代发货</span>
                            <span v-else-if="scope.row.orderStatus==2">已发货</span>
                            <span v-else-if="scope.row.orderStatus==3">已完成</span>
                            <span v-else>已关闭</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="支付状态" prop="payStatus" width="80"></el-table-column>
                    <el-table-column label="发货状态" prop="consignStatus" width="80">
                        <template slot-scope="scope">
                            <span v-if="scope.row.consignStatus==1">已发货</span>
                            <span v-else>未发货</span>
                        </template>
                    </el-table-column>


                    <el-table-column
                            label="操作">
                        <template slot-scope="scope">
                            <el-button @click="list(scope.row.id)" size="mini" size="small" type="primary">查看订单
                            </el-button>
                            <el-button @click="dele(scope.row.id)" size="mini" size="small" type="danger">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination-container">
                <el-pagination
                        :current-page.sync="currentPage"
                        :page-size="size"
                        :page-sizes="[10, 20, 30, 40]"
                        :total="total"
                        @current-change="fetchData"
                        @size-change="fetchData"
                        class="pagiantion"
                        layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
            <div class="add-form">
                <!--弹出窗口-->
                <el-dialog :title="title" :visible.sync="formVisible">
                    <div v-if="title=='拆分订单'">
                        <div class="filter-container">
                            <!--查询表单-->
                            <el-form :inline="true">
                                <el-form-item label="查询订单">
                                    <el-input class="filter-item" placeholder="查询拆分ID"
                                              v-model="searchMap.orderId"></el-input>
                                </el-form-item>
                                <el-button @click="fetchData()" class="dalfBut">查询</el-button>
                            </el-form>
                        </div>
                    </div>
                    <el-form label-width="80px">
                        <el-table :data="tableData" border
                                  style="width: 100%">
                            <el-form-item label="分类名称">
                                <el-table-column label="订单编号" prop="id" width="180"></el-table-column>
                            </el-form-item>
                            <!--                        <el-table-column label="订单编号" prop="id" v-model="pojo.id" width="180"></el-table-column>-->
                            <el-table-column label="收货人" prop="receiverContact"
                                             width="80"></el-table-column>
                            <el-table-column label="手机号码" prop="receiverMobile" width="180">

                            </el-table-column>
                            <el-table-column label="收货地址" prop="receiverAddress"
                                             width="160"></el-table-column>
                        </el-table>
                        <el-form-item>
                            <el-button @click="save()" type="primary">保存</el-button>
                            <el-button @click="formVisible = false">关闭</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>

        <div class="box" v-if="status==1">
            <div class="content">
                <div style="width: 100% ;height: 60px;background-color: rgba(249, 249, 249, 1)">

                    <el-row style="position: relative">
                        <span style="position: absolute;top: 20px;left: 80px">发货列表</span>

                        <!--                        <div style="position: absolute;top: 10px; right: 180px">-->
                        <!--                            <el-button type="primary">拆分订单</el-button>-->
                        <!--                            <el-button type="success">合并订单</el-button>-->
                        <!--                            <el-button type="info">打印发货单</el-button>-->
                        <!--                            <el-button type="warning" @click="findList()">批量发货</el-button>-->
                        <!--                            <el-button type="danger">导出订单</el-button>-->
                        <!--                        </div>-->
                    </el-row>
                </div>
                <el-form>
                    <el-table :data="tableData" border
                              style="width: 100%">
                        <el-form-item label="分类名称">
                            <el-table-column label="订单编号" prop="id" width="180"></el-table-column>
                        </el-form-item>
                        <!--                        <el-table-column label="订单编号" prop="id" v-model="pojo.id" width="180"></el-table-column>-->
                        <el-table-column label="收货人" prop="receiverContact"
                                         width="180"></el-table-column>
                        <el-table-column label="手机号码" prop="receiverMobile" width="180">

                        </el-table-column>
                        <el-table-column label="收货地址" prop="receiverAddress"
                                         width="160"></el-table-column>
                        <el-table-column label="配送方式" style="display: block" width="180">
                            <template slot-scope="scope">
                                <el-select placeholder="请选择配送方式"
                                           size="small" style="width:180px"
                                           v-model="tableData[scope.$index]['shippingName']">
                                    <el-option
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                            v-for="item in options">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>

                        <el-table-column label="物流单号" width="180">
                            <template slot-scope="scope">
                                <el-input @change="selfAdd(scope)"
                                          v-model="tableData[scope.$index]['shippingCode']"></el-input>
                            </template>
                        </el-table-column>

                    </el-table>
                    <el-form-item>
                        <el-button @click="this.status = 0">取消</el-button>
                        <el-button @click="batchSend()" type="success">提交</el-button>
                    </el-form-item>
                </el-form>


            </div>
        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,//添加窗口可见
                title: "编辑",
                orderType: "",//合并或者拆分订单
                imageUrl: '',
                ids: [],//批量发货的id数组
                status: 0,//判断是原来的order表，还是要批量发货的页面渲染
                options: [
                    {
                        value: 'o1',
                        label: '京东物流'
                    }, {
                        value: 'o2',
                        label: '顺丰物流'
                    }, {
                        value: 'o3',
                        label: '圆通物流'
                    }, {
                        value: 'o4',
                        label: '申通物流'
                    }, {
                        value: 'o5',
                        label: '韵达快递'
                    }],
                value: ''
            }
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/order/findPage.do?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                    console.log(this.tableData)
                });
            },
            save() {
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释
                axios.post(`/order/${this.pojo.id == null ? 'add' : 'update'}.do`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                });
            },
            edit(id) {
                this.formVisible = true // 打开窗口
                // 调用查询
                axios.get(`/order/findById.do?id=${id}`).then(response => {
                    this.pojo = response.data;
                    // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
                })
            },
            dele(id) {
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/order/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })
            },
            /* ****图片上传相关代码  如页面有图片上传功能放开注释 ****
            handleAvatarSuccess(res, file) {
                this.imageUrl = file.response;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }*/
            //跳转到订单详细列表
            list(id) {
                location.href = `orderFull.html?id=${id}`
            },
            handleSelectionChange(val) {
                this.ids = val
            },
            findList() {
                this.status = 1
                let ids = []
                ids = this.ids
                this.searchMap.ids = []
                ids.forEach(ele => {
                    this.searchMap.ids.push(ele["id"])
                })
                this.searchMap.consignStatus = "0"
                console.log(this.searchMap)
                axios.post("/order/findList.do", this.searchMap).then(res => {
                    console.log(res)
                    this.tableData = res.data;
                    console.log(this.tableData)
                    this.total = res.data.total;
                })
            },
            //批量发货
            batchSend() {
                axios.post("/order/batchSend.do", this.tableData).then(() => {
                    this.status = 0
                    this.searchMap = {}
                    this.fetchData();
                })
            },
            selfAdd(scope) {

                for (let index = 0; index < this.tableData.length - 1; index++) {
                    this.tableData[index + 1].shippingCode = (Number(this.tableData[index]['shippingCode']) + 1)
                }
                console.log(scope)
                console.log(this.tableData)

            }

        }
    })
</script>
</html>
